package creatType.Singleton;

public class Singleton1 {

    // 必须是private,不允许new对象出来
    private Singleton1() {
        System.out.println("I am Singleton1!");
    }

    private static Resource r;

    // 这里存在效率问题,每次线程访问都需要同步操作
    public static synchronized Resource getSingleton() {
        if (r == null)
            r = new Resource("Singleton1");
        return r;
    }
}
